<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>培训需求列表</title>


  <!-- Expand styles -->
  <link href="../css/app/app.css" rel="stylesheet">
  <link href="../css/fonts/font-awesome.min.css" rel="stylesheet">
  <link href="../css/app/default.css" rel="stylesheet">
  <link href="../css/mui/mui.css" rel="stylesheet">
  <link href="../css/mui/mui.picker.min.css" rel="stylesheet" />

</head>

<body>



  <!-- header -->
  <div>
    <div
      class="widget-default widget-body margin-b-5 padding-b-10 display-flex justify-content-between align-items-center">
      <div class="px-search mui-input-row mui-search" style="width: 88%;">
        <img src="../img/search-icon.png" alt="">
        <input class="mui-input-clear" type="text" name="" id="serach" placeholder="培训机构、地址">

      </div>
      <span class="font-16 gray serach">搜索</span>
    </div>

    <div class="widget-default padding-10 display-flex align-center justify-content-between margin-b-3">
      <div class="display-flex align-items-center justify-content-center width33" id="tranTypeCode">
        <span class="font-14 gray padding-r-10 elli1 tranTypeCode">培训类型</span>
        <span class="fa fa-angle-down gray"></span>
      </div>
      <div class="display-flex align-items-center justify-content-center width33" id="confirmStatus">
        <span class="font-14 gray padding-r-10 elli1 confirmStatus">状态</span>
        <span class="fa fa-angle-down gray"></span>
      </div>
      <div class="display-flex align-items-center justify-content-center width33" id="orderKey">
        <span class="font-14 gray padding-r-10 elli1 orderKey">默认排序</span>
        <span class="fa fa-angle-down gray"></span>
      </div>
    </div>

    <!-- 内容 -->
    <div id="pullrefresh" class="mui-content mui-scroll-wrapper" style="margin-top: 106px;">
      <div class="mui-scroll">
        <div id="contentList">
        </div>
      </div>
    </div>


  </div>


  <script src="../js/dsbridge.js"></script>
  <script src="../js/jquery.js"></script>
  <script src="../js/mui/mui.js"></script>
  <script src="../js/mui/mui.picker.min.js"></script>
  <script src="../js/layer.js"></script>
  <script src="../js/app/app-base.js"></script>
  <script src="../js/app/app-url.js"></script>
  <script src="../js/app/app-ajax.js"></script>
  <script>


    //地址选择
    var pickerTranTypeCode = new mui.PopPicker();
    var pickerConfirmStatus = new mui.PopPicker();
    var pickerSort = new mui.PopPicker();
    var keyWords = ''
    var tranTypeCode = ''
    var confirmStatus = ''
    var orderKey = ''
    var orderKeyList = [{
      value: '',
      text: '默认排序'
    }, {
      value: 'distance',
      text: '按距离排序 '
    }, {
      value: 'budget',
      text: '按预算排序 '
    }]
    var confirmStatusList = [{
      value: '',
      text: '全部'
    }, {
      value: '0',
      text: '等待报价 '
    }, {
      value: '1',
      text: '报价结束 '
    }, {
      value: '3',
      text: '对接成功'
    }]

    var page = 1;
    var limit = 10;
    var index = 0;
    //点赞数据index
    var praiseIndex = -1;
    //分享数据index
    var shareIndex = -1;
    var all_data = new Array();

    $(document).ready(function () {

      getServerData(url_businessdatamng_queryList, { pCode: 'TRAN_TYPE' })
      pickerConfirmStatus.setData(confirmStatusList);
      pickerSort.setData(orderKeyList);

      mui.init({
        pullRefresh: {
          container: '#pullrefresh',
          down: {
            auto: true, // 首次进入自动加载
            callback: pulldownRefresh
          },
          up: {
            contentrefresh: '正在加载...',
            callback: pullupRefresh
          }
        }
      });
    });

    /**
    * 下拉刷新具体业务实现
    */
    function pulldownRefresh() {
      page = 1;
      getData()
    }

    /**
    * 上拉加载具体业务实现
    */
    function pullupRefresh() {
      page++;
      getData()
    }

    function getData() {
      var data = {
        sourceType: 'web',
        userAccId: getUserId(),
        userId: getUserId(),
        tranTypeCode: tranTypeCode,
        page: page,
        limit: limit,
        keyWords: $('#serach').val(),
        confirmStatus: confirmStatus,
        longitude: localStorage.getItem("Longitude"),
        latitude: localStorage.getItem("Latitude"),
        orderKey: orderKey
      }
      getServerData(url_trandemandmgr_queryList, data);
    }
    function getServerDataSuccess(url, data) {
      switch (url) {
        //详情
        case url_trandemandmgr_queryList:
          var list = data.data;
          var html_data = "";
          if (page == 1) {
            index = 0;
            all_data.length = 0;
          }
          if (list.length > 0) {
            for (var i = 0; i < list.length; i++) {
              all_data.push(list[i]);
              var item = list[i]
              var imgs = ''
              if (item.confirmStatus == 0) {
                imgs = '<img class="pxsuccess-img" src="../img/px-going.png" alt="">'
              } else if (item.confirmStatus == 1) {
                imgs = '<img class="pxsuccess-img" src="../img/px-ending.png" alt="">'
              } else if (item.confirmStatus == 2) {
                imgs = '<img class="pxsuccess-img" src="../img/px-fail.png" alt="">'
              } else if (item.confirmStatus == 3) {
                imgs = '<img class="pxsuccess-img" src="../img/px-success.png" alt="">'
              }
              var address = item.provinceName + item.cityName + item.countyName
              html_data += '<div class="margin-b-10 trainDemand" confirmStatus="' + item.confirmStatus + '" id="' + item.id + '">' +
                '<div class="trade-list widget-body widget-default margin-b-1">' +
                '<div class="display-flex align-items-center margin-b-10">' +
                ' <span class="px-content font-15 tuli-bg-b elli1">' + item.tranTypeName + '</span>' +
                '<p class="black1 font-16 font-weight no-margin elli1 padding-r-10">' + item.title + '</p>' +
                '  </div>' +
                imgs +
                ' <div class="display-flex align-items-center justify-content-between padding-t-5">' +
                ' <p class="font-12 gray no-margin">主办方：' + item.tranSponsors + '</p>' +
                ' <span class="font-16 font-weight red">￥' + item.budgetShow + '</span>' +
                '</div>' +
                '  <div class="display-flex align-items-center justify-content-between">' +
                ' <p class="font-12 gray no-margin">培训地址：' + address + '</p>' +
                ' <span class="font-12 gray">' + item.quoteNum + '人已报价</span>' +
                ' </div>' +
                ' </div>' +
                ' </div>'
              index++;
            }
            ;
          }
          if (page == 1) {
            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
            if (list.length > 0) {
              mui('#pullrefresh').pullRefresh().refresh(true);
            }
            $("#contentList").html(html_data);
          } else {
            $("#contentList").append(html_data);
            mui('#pullrefresh').pullRefresh().endPullupToRefresh(list.length != limit);
          }
          break;
        case url_businessdatamng_queryList:
        var classificationData = data.data.map(item => {
            return { text: item.name, value: item.code }
          })
          classificationData.unshift({ text: '全部', value: '' })
          pickerTranTypeCode.setData(classificationData);
          break;
        case url_oper_action_cancel + '?type=praise':

          //取消点赞
          $(".widget-body[id='" + praiseIndex + "']").find(".praiseImg").attr("src", "../img/zai.png");
          var $praiseNum = $(".widget-body[id='" + praiseIndex + "']").find(".praiseNum");
          var praiseNum = Number($praiseNum.text()) - 1;
          if (praiseNum < 0) {
            praiseNum = 0;
          }
          $praiseNum.text(praiseNum);
          break;
      }
    }

    function getServerDataFailed(url, data) {
      mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
      mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
    }
    $("#tranTypeCode").on("tap", function () {
      pickerTranTypeCode.show(function (item) {
        tranTypeCode = item[0].value;
        var address = item[0].text;
        getData()
        $(".tranTypeCode").html(address);
      });
    })

    $("#confirmStatus").on("tap", function () {
      pickerConfirmStatus.show(function (item) {
        confirmStatus = item[0].value;
        var address = item[0].text;
        getData()
        $(".confirmStatus").html(address);
      });
    })

    $("#orderKey").on("tap", function () {
      pickerSort.show(function (item) {
        orderKey = item[0].value;
        var address = item[0].text;
        getData()
        $(".orderKey").html(address);
      });

    })

    mui("#contentList").on('tap', '.trainDemand', function () {
      var bol = this.getAttribute("confirmstatus")
      localStorage.setItem("tranDemand_Id", this.id);
      if (bol === '0') {
        localStorage.setItem("tranDemandDetail_sourceType", 'demand-list');
      } else {
        localStorage.setItem("tranDemandDetail_sourceType", 'my-quote');
      }
      dsBridge.call("goDetail");
    });
    $('.serach').click(function () {
      page = 1;
      getData()
    })

  </script>

</body>

</html>